package com.android.formula.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.formula.R;
import com.android.formula.model.Subject;
import com.android.formula.utils.CommonUtils;
import com.android.formula.utils.Constants;

public class SubjectListAdapter extends TBaseAdapter<Subject> {

	public SubjectListAdapter(Context context, List<Subject> items) {
		super(context, items);
	}

	@Override
	protected View getView(View convertView) {
		convertView = mInflater.inflate(R.layout.item_gridview, null, false);
		ViewHolder viewHolder = new ViewHolder(); // new ViewHolder
		viewHolder.init(convertView); // init views in ViewHolder
		convertView.setTag(viewHolder);
		return convertView;
	}

	@Override
	public void freeMemoryView(View v) {
	}

	@Override
	protected void setViews(View view, Subject item) {
		ViewHolder viewHolder = (ViewHolder) view.getTag();
		viewHolder.titleTv.setText(item.getSubjectName());
		CommonUtils.setImageFromDrawable(mContext, Constants.IMAGE_TYPE_SUBJECT
				+ item.getSubjectId(), viewHolder.itemImageIv);
	}

	protected class ViewHolder {
		public TextView titleTv;

		public ImageView itemImageIv;

		public void init(View convertView) {
			itemImageIv = (ImageView) convertView
					.findViewById(R.id.item_gridview_img);
			titleTv = (TextView) convertView
					.findViewById(R.id.item_gridview_txt);
		}
	}
}
